//
//  ITAFNDownloadViewController.m
//  InduceTool
//
//  Created by 魏延龙 on 2020/9/9.
//  Copyright © 2020 魏延龙. All rights reserved.
//

#import "ITDownloadTaskViewController.h"
#import <AFNetworking/AFNetworking.h>
#import "ITDownloader.h"
#import "ITDownloaderManager.h"
@interface ITDownloadTaskViewController ()

@property (nonatomic, strong) ITDownloader *downloader;

@end

@implementation ITDownloadTaskViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupViews];
    
}

-(void)setupViews {
    UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [startBtn setTitle:@"开始" forState:UIControlStateNormal];
    startBtn.frame = CGRectMake(50, 200, 100, 44);
    [self.view addSubview:startBtn];
    [startBtn addTarget:self action:@selector(startAction) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *pauseBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [pauseBtn setTitle:@"暂停" forState:UIControlStateNormal];
    pauseBtn.frame = CGRectMake(50, 250, 100, 44);
    [self.view addSubview:pauseBtn];
    [pauseBtn addTarget:self action:@selector(test1) forControlEvents:UIControlEventTouchUpInside];
    [pauseBtn addTarget:self action:@selector(test2) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    cancelBtn.frame = CGRectMake(50, 300, 100, 44);
    [self.view addSubview:cancelBtn];
    [cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *cancelOneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancelOneBtn setTitle:@"取消某个" forState:UIControlStateNormal];
    cancelOneBtn.frame = CGRectMake(50, 350, 100, 44);
    [self.view addSubview:cancelOneBtn];
    [cancelOneBtn addTarget:self action:@selector(cancelOneAction) forControlEvents:UIControlEventTouchUpInside];
    
    
}

-(void)startAction{
    [[ITDownloaderManager sharedInstance] startDownloadWithURLStr:@"http://220.249.115.46:18080/wav/Lovey_Dovey.mp4" toPath:nil progress:^(uint64_t receivedLength, uint64_t totalLength, NSInteger remainingTime, float progress) {
        NSLog(@"[ITITDownload] 下载进度 %.2f",progress);
    } error:^(NSError * _Nonnull error) {
        NSLog(@"[ITITDownload] 下载失败 %@",error.localizedDescription);
    } complete:^(BOOL downloadFinished, NSString * _Nonnull pathToFile) {
        NSLog(@"[ITITDownload] 下载成功 %@",pathToFile);
    }];
}

-(void)pauseAction{
    
}

-(void)cancelAction{
    [[ITDownloaderManager sharedInstance] cancleAll];
}

-(void)cancelOneAction{
    [[ITDownloaderManager sharedInstance] cancelWithUrl:@"http://220.249.115.46:18080/wav/Lovey_Dovey.mp4"];
}

-(void)test1 {
    NSLog(@"test1");
}
-(void)test2 {
    NSLog(@"test2");
}

@end
